#pragma once
#include "ErrorCommon.h"

namespace ErrorHandling {

enum FndErrorId
{
	EID_FND_BASE = EID_FOUNDATION_BASE,
	EID_FND_TIMEOUT,
	EID_FND_VERSION,
	EID_FND_RANGE,
	EID_FND_UNHANDLED_EXCEPTION,
	EID_FND_SEND_MESSAGE,

	EID_FND_WRONG_PAYLOAD,   // payload isn't what is expected
	EID_FND_NOT_INITIALIZED, // AO is not initialized when recieiving an unexpected message
	EID_FND_PROGRAMMING,     // programming error (from an assert that should never fail)

	//
	// Job Server Errors
	//
	EID_CTRL_JOB_SERVER_BASE = EID_CONTROL_BASE,
	EID_JOB_NO_THREADS,         // no more threads =(
	EID_NO_JOB,                 // cannot abort thread as it is not running
	EID_JOB_OWNERSHIP,          // cannot abort thread as you are not the owner
	EID_JOB_NO_IDS,             // ran out of job IDs (have 32K jobs running&queued!)
	EID_JOB_INVALID_ID,
	EID_JOB_START_FAILED,
	EID_JOB_ABORTED,
	EID_JOB_DIED,
	EID_JOB_FAILED,

	EID_DIRECTOR_NO_SCHEDULE,		// no pre-loaded schedule to re-run
	EID_DIRECTOR_INITIALIZATION,	// cannot initialize the director
	EID_JOBSERVER_CREATION,			// failure creating job server
	EID_IMAGESERVER_CREATION,		// failure creating image server
	EID_COLLECTOR_CREATION,			// failure creating collector
	EID_MAPPER_CREATION,			// failure creating mapper
	EID_ANALYZER_CREATION,			// failure creating analyzer

	//
	// Image Server Errors
	//
	EID_CTRL_IMAGE_SERVER_BASE = EID_CONTROL_BASE + 1000,
	EID_IMAGE_SET_ID_INVALID,       // the set ID was not found by the Image Server
	EID_CANNOT_ALLOCATE,            // problem allocating images for an image set
	EID_SETS_NOT_ALL_RELEASED,      // one of the sets to be released is locked!
	EID_DUPLICATE_SETS_LOADED,      // sets loaded include duplicate ID
	EID_REPOSITORY_ERROR,
	EID_SW_ERROR_RECOVERY_TIMEOUT,  // clients did not release image sets in time after software error.
	EID_INVALID_IMAGE_SET_TYPE,     // an invalid ImageSet type was requested from the ImageSetFactory

	//
	// Director Errors
	//
	EID_CTRL_DIRECTOR_BASE = EID_CONTROL_BASE + 2000,
	EID_SCHEDULE_READ_FAILURE,
	EID_TEMPLATE_READ_FAILURE,

	//
	// Analyzer Errors
	//
	EID_CTRL_ANALYZER_BASE = EID_CONTROL_BASE + 3000,
	EID_ANALYZER_TIMEOUT,
	EID_ANALYSIS_JOB_FAILED,

	//
	// General CAN errors
	//
	EID_CTRL_CANOPEN_BASE = EID_CONTROL_BASE + 4000,
	EID_UNEXPECTED_CAN_MSG,			//An unexpected CAN message is received which should 
									//have been recieved previously or not expected at
									//at this point of time
	EID_UNEXPECTED_RESPONSE_MSG,	//An unsolicited response message is received 
	EID_EMERGENCY_MSG,				//Elmo drive has sent an emergency message
	EID_NETWORK_EVENT,				//A network event has occurred like heartbeat
									//failure or tx/rx queue overflow etc.
	EID_SEND_MESSAGE_ERROR,			//Send message has thrown an error

	//
	// Robot Errors
	//
	EID_CTRL_ROBOT_BASE = EID_CONTROL_BASE + 5000,
	EID_ROBOT_INIT_FAILED,			// Robot Initialization failed
	EID_ROBOT_GENERAL_ERROR,		//General error in robot
	EID_ROBOT_TIMEOUT_ERROR,		//Robot Time out error.
	EID_HOME_FIRST_STAGE_FAILED,	//Homing first stage failed
	EID_HOME_SECOND_STAGE_FAILED,	//Homing second stage failed
	EID_LOAD_PVT_FAILED,			//Load PVT failed
	EID_LOAD_PVT_CAN_STATUS_NOT_OK, //Load PVT failed
	EID_PERFORM_PVT_MOVE_FAILED,	//Perform PVT move failed
	EID_PTP_MOVE_FAILED,			//Point to Point move failed
	EID_UNEXPECTED_COMMAND,			//unexpected command from the collection coordinator.
									//May be in the middle of another command execution
	EID_TIMESTAMP_TX_FAILED,		//Time stamp message transmission failed

	//
	// Conveyor/Platform Errors
	//
	EID_CTRL_CONVEYOR_PLATFORM_BASE = EID_CONTROL_BASE + 6000,
	EID_CONVEYOR_PLATFORM_INIT_FAILED,          //Initialization failed
	EID_PLATFORM_SET_INDICATOR_FAILED,          //Set indicator failed. The indiactor state defined may be unknown
	EID_CONVEYOR_PLATFORM_UNEXPECTED_COMMAND,   //The last command was not expected at this time or unsupported
	EID_COMMAND_EXECUTION_FAILED,               //Execution of the last command failed

	EID_CONVEYOR_ERRORS_FROM_PLC = EID_CTRL_CONVEYOR_PLATFORM_BASE + 10, //this is the begining of the plc error

    EID_CONVEYOR_BYPASS_SENSOR_BLOCKED_ERROR,	//Entry and Exit optos blocked
	EID_CONVEYOR_WIDTH_NOT_AT_SPECIFIED_ERROR,	//Change conveyor width complete but conveyor is not at specified width
	EID_CONVEYOR_NOT_HOMED_ERROR,				//Autowidth not homed. Close application and cycle hardware power to retry
    EID_CONVEYOR_INVALID_A_ERROR,				//Invalid Acceleration specified. Please check configuration file
	EID_CONVEYOR_INVALID_SI_ERROR,				//Invalid Internal Speed specified. Please check configuration file
    EID_CONVEYOR_INVALID_SA_ERROR,				//Invalid Acquired Speed. Please check configuration file
    EID_CONVEYOR_INVALID_SS_ERROR,				//Invalid Slowdown Speed. Please check configuration file
	EID_CONVEYOR_INVALID_SR_ERROR,				//Invalid Release Speed. Please check configuration file
	EID_CONVEYOR_INVALID_WIDTH_ERROR,			//Invalid Width Specified
	EID_CONVEYOR_WIDTH_PROX_BLOCK_ERROR,		//Opto blocked, cannot change conveyor width
    EID_CONVEYOR_LOW_AIR_PSI_MESSAGE,			//Low Air Pressure
    EID_CONVEYOR_RELEASE_STATE_ERROR,			//Command mismatch in Conveyor; Release Command received
	EID_CONVEYOR_RELEASE_PANEL_FREE_ERROR,		//Panel release error - timeout                
    EID_CONVEYOR_PRERELEASE_PANEL_FREE_ERROR,	//Panel release error - timeout
	EID_CONVEYOR_CHANGE_WIDTH_STATE_ERROR,		//Command mismatch in Conveyor; Change Width command received
	EID_CONVEYOR_CHANGE_WIDTH_HOMED_ERROR,		//Attempted conveyor width change without homing                    
	EID_CONVEYOR_PRERELEASE_STATE_ERROR,		//Command mismatch in Conveyor; Pre-release command received
	EID_CONVEYOR_PANEL_SECURE_ERROR,			//Panel load error - timeout secure panel                        
	EID_CONVEYOR_SLOW_SENSOR_ERROR,				//Entry and Slow-down optos blocked                            
	EID_CONVEYOR_SECURE_PANEL_END_WITH_ERRORS,	//Panel load error - timeout secure panel                              
	EID_CONVEYOR_ALIGN_BEFORE_SLOW_ERROR,		//Slow-down and Align optos blocked                                  
	EID_CONVEYOR_RELOAD_PANEL_FREE_ERROR,		//Command mismatch in Conveyor; Reload command is received                                      
	EID_CONVEYOR_RELOAD_PANEL_STATE_ERROR,		//Command mismatch in Conveyor; Reload command is received                                          
	EID_CONVEYOR_PANEL_FREE_WITH_ERRORS,		//Panel unsecure error                                              
	EID_CONVEYOR_LOAD_PANEL_SENSOR_BLOCKED_ERROR,//Panel load error - opto blocked                                                  
	EID_CONVEYOR_FREE_PANEL_STOP_UP_ERROR,		//Panel unsecure error - board stop engaged
	EID_CONVEYOR_FREE_PANEL_OPTO_BLOCK_ERROR,	//Panel unsecure error - opto blocked                                                          
	EID_CONVEYOR_LOAD_PANEL_NOT_RELEASED_ERROR,	//Command mismatch in Conveyor; Load command is received                                                              
	EID_CONVEYOR_BOARD_STOPPED_TIMEOUT_ERROR,	//Board stop error - timeout                                                                  
	EID_CONVEYOR_TO_UNSTOP_ERROR,				//Board stop error - timeout                                                                      
	EID_CONVEYOR_TO_ACQ_ERROR,					//Panel load error - Timeout acquire panel                                                                          
	EID_CONVEYOR_TO_ALIGN_ERROR,				//Panel load error - Timeout Alignment Opto                                                                              
	EID_CONVEYOR_TO_RELEASE_ERROR,				//Panel release error - timeout                                                                                  
	EID_CONVEYOR_TO_SEARCH_ERROR,				//Panel reload error - timeout                                                                                      
	EID_CONVEYOR_TO_SLOW_ERROR,					//Panel load error - Timeout Slowdown Opto                                                                                          
	EID_CONVEYOR_TO_SMEMA_ERROR,				//SMEMA timeout                                                                                              
	EID_CONVEYOR_TO_EXIT_TIMEOUT,				//Panel release error - Timeout Exit opto                                                                                                  
	EID_CONVEYOR_TO_EXIT_ERROR,					//Panel release error                                                                                                      
	EID_CONVEYOR_TO_LIFTED_ERROR,				//Timeout Panel Lift                                                                                                          
	EID_CONVEYOR_TO_UNCLAMP_ERROR,				//Timeout Panel Unclamp                                                                                                              
	EID_CONVEYOR_TO_CLAMP_ERROR,				//Timeout Panel Clamp                                                                                                              
	EID_CONVEYOR_TO_UNLIFT_ERROR,				//Timeout Panel Unlift
	//broad-term error
	EID_CONVEYOR_HARDWARE_FAULT_ERROR, 			//A general hardware fault error has occurred    
	//broad-term error
	EID_CONVEYOR_PANEL_ERROR,			 		//A general panel error has occurred    
    EID_CONVEYOR_PASS_THRU_SENSOR_BLOCKED_ERROR,//Unable to enter pass-through mode - Entry and Exit optos blocked    
	EID_CONVEYOR_IN_BYPASS_MODE_ERROR,			//Conveyor is in bypass mode
	EID_CONVEYOR_HOME_PROX_BLOCK_ERROR,			//Opto blocked, cannot perform auto-width homing
	EID_CONVEYOR_TO_HOMING_ERROR,				//Timeout performing Auto-width homing. Close application and cycle hardware power to retry

	EID_CONVEYOR_INVALID_BUFFER_A_ERROR,
    EID_CONVEYOR_INVALID_BUFFER_SI_ERROR,
	EID_CONVEYOR_INVALID_BUFFER_SI_DOWNSTREAM_ERROR,
	EID_CONVEYOR_INVALID_BUFFER_SA_ERROR,
	EID_CONVEYOR_INVALID_BUFFER_SS_ERROR,
	EID_CONVEYOR_INVALID_BUFFER_SR_ERROR,
	EID_CONVEYOR_TO_BUFFER_ACQ_ERROR,
	EID_CONVEYOR_TO_BUFFER_RELEASE_ERROR,
	EID_CONVEYOR_BUFFER_SENSOR_BLOCKED_ERROR,
	EID_CONVEYOR_BUFFER_TO_EXIT_ERROR,			//Timeout Exit opto - Buffer Section
	EID_CONVEYOR_CANNOT_RESET_BELT_SLAVE_ERROR,	//Unable to reset fixed belt drive
	EID_COLLISION_DETECTED,						//Collision detected
	EID_PANEL_LENGTH_EXCEEDED_BUFFER_SPEC_ERROR,//panel length exceeded buffer spec of 300mm

	//
	// Height reconstructor Errors
	//
	EID_CTRL_HEIGHT_RECONSTRUCTOR_BASE = EID_CONTROL_BASE + 7000,
	EID_RECONSTRUCTOR_LOST_IMAGE,
	EID_HEIGHT_DISTORTION_CORRECTION,

	//
	// Mapper Errors
	//
	EID_CTRL_MAPPER_BASE = EID_CONTROL_BASE + 8000,

	//
	// Coordinator Errors
	//
	EID_CTRL_COORDINATOR_BASE = EID_CONTROL_BASE + 9000,
	EID_TIMEOUT_WAITING_FOR_IMAGE,
	EID_TGEN_MOTION_LIMITS_EXCEEDED,             // TrajectoryGenerator and/or PathBuilder were given an out-of-range motion directive

	//
	// Sensor Errors
	//
	EID_CTRL_SENSOR_BASE = EID_CONTROL_BASE + 10000,
	EID_SENSOR_INITIALIZE_CAMERA,
	EID_SENSOR_INITIALIZE_MIDDLEMAN,
	EID_SENSOR_INVALID_AOI_SETUP_HANDLE,
	EID_SENSOR_SET_TRIGGERS,
	EID_SENSOR_PUSH_TRIGGERS,
	EID_SENSOR_GET_SCAN_STATUS,
	EID_SENSOR_GET_GAIN_OFFSET,
	EID_SENSOR_RESET_ENCODER_COUNTS,
	EID_SENSOR_BEGIN_ENCODER_SYNC,
	EID_SENSOR_END_ENCODER_SYNC,
	EID_SENSOR_TRIGGER_LED_IMAGE,
	EID_SENSOR_CALIBRATION_READ_FAILED,
	EID_SENSOR_CALIBRATION_CRC_FAILED,

	//
	// Middleman (i.e. MiddlemanWrapper/MiddlemanLogger) errors:
	//
	EID_CTRL_MIDDLEMAN_BASE = EID_CONTROL_BASE + 10500,
	EID_MIDDLEMAN_OPEN,                          // Failed to open serial comm / USB connection to middleman (check USB/COM port)
	EID_MIDDLEMAN_CLOSE,                         // Failed to close serial comm / USB connection to middleman
	EID_MIDDLEMAN_LOGGING_ENABLE,                // Failed to enable middleman logging (bad filename/path? drivers? USB/COM port?)
	EID_MIDDLEMAN_LOGGING_DISABLE,               // Failed to disable middleman logging
	EID_MIDDLEMAN_CLEAR_TRIGGER_SEND_BUFFER,     // Failed to clear the *DLL's* trigger-sending buffer (not the middleman's trigger queue)
	EID_MIDDLEMAN_SEND_RAW_STRING,               // A debug-backdoor command sent as a raw text string over serial port has failed
	EID_MIDDLEMAN_READ_CAMERA_REGISTER,          // Self-explanatory (but check the camera state; has it locked up?)
	EID_MIDDLEMAN_WRITE_CAMERA_REGISTER,         // Self-explanatory (but check the camera state; has it locked up?)
	EID_MIDDLEMAN_READ_REGISTER,                 // This refers to any of the middleman scan-variable/diagnostic/system-parameter registers
	EID_MIDDLEMAN_WRITE_REGISTER,                // This refers to any of the middleman scan-variable/diagnostic/system-parameter registers
	EID_MIDDLEMAN_PUSH_TRIGGER,                  // Pushing a camera trigger onto the CoMiddleman DLL's trigger-send buffer failed
	EID_MIDDLEMAN_PUSH_END_OF_SCAN,              // Sending a special end-of-scan marker to the middleman's trigger queue failed
	EID_MIDDLEMAN_SEND_COMMAND,                  // Issuing one of the middleman commands 'c00' through 'c11' failed
	EID_MIDDLEMAN_READ_EEPROM,

	//
	// Frame grabber Errors
	//
	EID_CTRL_FRAMEGRABBER_BASE = EID_CONTROL_BASE + 11000,
	EID_FRAME_GRABBER_TASK,
	EID_BAD_IMAGE_HEADER,
	EID_BAD_HEADER_CHECKSUM,
	EID_BAD_ROW_CHECKSUM,
	EID_Y_ENCODER_INTERPOLATION,
	EID_IMAGE_TRIGGER_COUNTS,
	EID_XYZ_ENCODER_POSITION,
	EID_STROBE_MONITOR,
	EID_TRIGGER_MODE,

	// 
	// BitFlow (i.e. BitFlowWrapper) Errors:
	//
	EID_CTRL_BITFLOW_BASE = EID_CONTROL_BASE + 11500,
	EID_BITFLOW_BOARD_OPEN,                     // Hardware framegrabber not installed?
	EID_BITFLOW_BOARD_CLOSE,                    // Should never happen -- BiBrdClose() always returns OK
	EID_BITFLOW_CAMERA_FILE_OPEN,               // File not found in C:\BitFlowSDK\Config\R64
	EID_BITFLOW_CAMERA_FILE_CLOSE,              // Problem releasing resources
	EID_BITFLOW_CAMERA_FILE_ACTIVATE,           // Bad camera file?
	EID_BITFLOW_CAMERA_FILE_READ,               // Reading a specific value failed
	EID_BITFLOW_IMAGE_DIMENSIONS,               // Bad image dimensions (columns not a multiple of 16?)
	EID_BITFLOW_DMA_SETUP,                      // Unable to set up DMA tables
	EID_BITFLOW_DMA_CLEANUP,                    // Unable to tear down DMA tables
	EID_BITFLOW_DMA_BUFFER_ALLOC,               // BitFlow DMA buffer allocation failed
	EID_BITFLOW_DMA_BUFFER_RELEASE,             // BitFlow DMA buffer cleanup failed
	EID_BITFLOW_DMA_BUFFER_SIZE,                // Tried to specify a circular buffer of <2 frames?
	EID_BITFLOW_ACQUISITION_DEFINE,             // Unable to define a new acquisition type
	EID_BITFLOW_ACQUISITION_ACTIVATE,           // Unable to activate a defined acquisition type
	EID_BITFLOW_ACQUISITION_QUERY,              // Unable to query active parameters
	EID_BITFLOW_ACQUISITION_START,              // Unable to begin image capture
	EID_BITFLOW_ACQUISITION_STOP,               // Unable to abort image capture

	//
	// System manager Errors
	//
	EID_CTRL_SYSTEM_MANAGER_BASE = EID_CONTROL_BASE + 12000,
	EID_SYSTEM_COMPONENT_NOT_RESPONDING,

	//
	// Machine control Errors
	//
	EID_CTRL_MACHINE_CONTROL_BASE = EID_CONTROL_BASE + 13000,

	// NOTE:  EID_Legacy_BASE currently begins at EID_CONTROL_BASE + 40000.
	//        If too many new error groups are added here, just increase 
	//        the value of EID_Legacy_BASE to make room.
};

} // end namespace
